package projectATM2;

import java.awt.*;
import java.awt.event.*;
import java.lang.Integer;
import java.text.DecimalFormat;

import javax.swing.*;

public class ATMGui2 extends JPanel {
	private static JTextField directions = new JTextField();
	private static JTextField balanceDisplay = new JTextField(10);
	private JButton addFunds = new JButton("Add Funds");
	private JButton withdrawFunds = new JButton("Withdraw Funds");
	private JButton balanceCheck = new JButton("Check Balance");
	private JTextArea input = new JTextArea();
	static ATMFunctions2 atm = new ATMFunctions2();

	public ATMGui2() {
		setLayout(new BorderLayout());
		balanceDisplay.setEditable(false);
		Font font = new Font("Lucida Console", Font.PLAIN, 30);
		balanceDisplay.setFont(font);
		add(input, BorderLayout.NORTH);
		add(balanceDisplay, BorderLayout.CENTER);

		JPanel buttonPanel1 = new JPanel();
		buttonPanel1.setLayout(new GridLayout(1, 3, 0, 0));
		buttonPanel1.add(addFunds);
		buttonPanel1.add(withdrawFunds);
		buttonPanel1.add(balanceCheck);

		add(buttonPanel1, BorderLayout.SOUTH);

		addFunds.addActionListener(new addFundsAL());
		withdrawFunds.addActionListener(new withdrawFundsAL());
		balanceCheck.addActionListener(new balanceCheckAL());
	}

	public class addFundsAL implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			String amount = input.getText();
			int money = Integer.parseInt(amount);
			atm.addFunds(money);
			balanceDisplay.setText("");
		}
	}

	public class withdrawFundsAL implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			String amount = input.getText();
			int money = Integer.parseInt(amount);
			atm.withdrawFunds(money);
			balanceDisplay.setText("");
		}
	}

	public class balanceCheckAL implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			atm.printBalance();
		}
	}
	
	public static void updateDisplay(int balance){
		balanceDisplay.setText("" + balance);
	}
	
	public static String toChange(double x) {
		x = x / 100;
		DecimalFormat intoChange = new DecimalFormat("#.00");
		return intoChange.format(x);
	}
	
}